﻿using DAL;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Forms.DataVisualization.Charting;

namespace word.UserControls
{
    public partial class ChartMessage : UserControl
    {
        public ChartMessage()
        {
            InitializeComponent();
        }

        private void ChartMessage_Load(object sender, EventArgs e)
        {
            showGoodsDiscount();
            ShowUserMessage();
            showOrdersMessage();
        }

        /// <summary>
        /// 图标展示商品信息
        /// </summary>
        public void showGoodsDiscount()
        {
            ChartHelper.AddSeries(Chart_Discount, new string[] { "商品价格", "商品折扣", "库存数量" }, new SeriesChartType[] { SeriesChartType.Spline, SeriesChartType.Spline, SeriesChartType.Spline });
            ChartHelper.SetAsisxInterval(Chart_Discount, 1);

            ChartHelper.DataBindSourceChart(Chart_Discount, "Goods", 0, "g_name", "g_Price");
            ChartHelper.DataBindSourceChart(Chart_Discount, "Goods", 1, "g_name", "g_Discount");
            ChartHelper.DataBindSourceChart(Chart_Discount, "Goods", 2, "g_name", "g_Number");
            Chart_Discount.Series[1].YAxisType = AxisType.Secondary;
        }

        /// <summary>
        /// 显示用户信息
        /// </summary>
        public void ShowUserMessage()
        {
            string sql = "SELECT u_Type, COUNT(u_Type) u_number from Users GROUP BY u_Type";
            ChartHelper.AddSeries(Chart_ShowUserMessage, new string[] { "用户数量" }, new SeriesChartType[] { SeriesChartType.Column });
            ChartHelper.SetAsisxInterval(Chart_ShowUserMessage, 1);
            ChartHelper.DataBindSourceChartWithSql(Chart_ShowUserMessage, sql, 0, "u_Type", "u_number");
        }


        /// <summary>
        /// 显示订单信息
        /// </summary>
        public void showOrdersMessage()
        {
            string sql = "SELECT  o_SendMode ,COUNT(o_SendMode) o_number FROM Orders group BY o_SendMode";
            ChartHelper.AddSeries(Chart_ShowOrders, new string[] { "订单信息" }, new SeriesChartType[] { SeriesChartType.Column });
            ChartHelper.SetAsisxInterval(Chart_ShowOrders, 1);
            ChartHelper.DataBindSourceChartWithSql(Chart_ShowOrders, sql, 0, "o_SendMode", "o_number");
        }
    }
}
